﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using WooCoo.Data;
using WooCoo.ObjectModel.ManagedProperty;
using WooCoo.Reflection;
using WooCoo.Tools;

namespace WooCoo.ObjectModel
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public static class P<T> where T : Entity
    {
        #region register
        public static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, P>> propertyExp, P defaultValue = default(P))
        {
            var propertyInfo = Reflect<T>.GetProperty(propertyExp);
            string friendlyName = TypeHelper.GetFriendlyNameFromAttributes(propertyInfo);
            //string mappingName = ColumnAttribute.GetColumnName(propertyInfo);
            var p = PropertyInfoFactory.Factory.Create<P>(typeof(T), propertyInfo.Name, defaultValue, friendlyName);
            return PropertyInfoRepository.Instance.RegisterProperty<P>(typeof(T), p);
        }

        #region GetPropertyName

        private static string GetPropertyName<P>(Expression<Func<T, P>> propertyExp)
        {
            return Reflect<T>.GetProperty(propertyExp).Name;
        }

        #endregion

        #endregion
    }
}
